<?php
declare (strict_types=1);

namespace app\service;

use think\facade\Db;
use think\Request;
use think\response\Json;

class checkField extends \think\Service
{
    /**
     * 注册服务
     *
     * @return mixed
     */
    public function register()
    {
        //
    }

    /**
     * 执行服务
     *
     * @return mixed
     */
    public function boot()
    {
        //
    }

    /**
     * 校验手机号是否注册过
     * @param $phone
     * @return boolean
     */
    public function accountCheckPhone($phone, $id): bool
    {
        if (isset($id) && !empty($id)) {
            $result = Db::name('user')->where('id', '<>', $id)->where(['mobile' => $phone])->count();
        } else {
            $result = Db::name('user')->where(['mobile' => $phone])->count();
        }
//        echo Db::getLastSql();
        return $result == 0;
    }

    /**
     * 校验机构名称是否重复
     * @param $name
     * @param $id
     * @return bool
     */
    public function checkInstitutionName($name, $id)
    {
        if (isset($id) && !empty($id)) {
            $result = Db::name('organ')->where('id', '<>', $id)->where(['name' => $name])->count();
        } else {
            $result = Db::name('organ')->where(['name' => $name])->count();
        }
//        return Db::getLastSql();
        return $result == 0;
    }
}
